import {AuthInterface} from "../interface/AuthInterface";
import {AUTH} from "../types";

const initState: AuthInterface = {
    hasLogin: false, // 初始化登录状态
    token: "",
    userInfo: null, // 用户信息
    loginInfo: null,
}
const AuthReducer = (state: AuthInterface = initState, action: any) => {
    switch (action.type) {
        case AUTH.LOGIN:
            return Object.assign({}, state, {
                hasLogin: action.payload.hasLogin,
                token: action.payload.token
            });
        case AUTH.LOGOUT:
            return Object.assign({}, state, {
                hasLogin: action.payload.hasLogin,
                token: action.payload.token
            });
        case AUTH.TOKEN:
            return Object.assign({}, state, action.payload);
        case AUTH.USERINFO:
            return Object.assign({}, state, action.payload);
        case AUTH.LOGIN_INFO:
            return Object.assign({}, state, {loginInfo: action.payload});
        default:
            return state;

    }

}
export default AuthReducer;
